import { setCustomerBlackList, updateBlackListSetBySnCodeId } from '@/api/users'
import { ref } from 'vue'

/**
 * 更新黑名单设置
 */
export const useUpdateCustomerBlackListSet = () => {
  // 更新设置加载
  const updateSetLoading = ref(false)

  /**
   * 更新设置
   * @param {Array<string>} ids - 公司id集合
   * @param {Boolean} isJoinBlackList - 是否加入黑名单
   */
  const updateSet = async (ids: Array<string>, isJoinBlackList: boolean) => {
    updateSetLoading.value = true
    const res = await setCustomerBlackList(ids, isJoinBlackList)
    updateSetLoading.value = false
    return res.data
  }

  return {
    updateSetLoading,
    updateSet,
  }
}

/**
 * 更新产品的黑名单设置
 */
export const useUpdateGoodBlackListSet = () => {
  // 更新黑名单设置加载
  const updateBlackLIstSetLoading = ref(false)

  /**
   * 更新黑名单设置
   * @param {String} id - 条码id
   * @param {Boolean} isJoinBlackList - 是否加入黑名单
   */
  const updateSet = async (id: string, isJoinBlackList: boolean) => {
    updateBlackLIstSetLoading.value = true
    const res = await updateBlackListSetBySnCodeId(id, isJoinBlackList)
    updateBlackLIstSetLoading.value = false
    return res.data
  }

  return {
    updateBlackLIstSetLoading,
    updateSet,
  }
}
